﻿Ext.regController('ftController', {

    'index': function (options) {

        if (!FlyTalk.views.mainView) {
			//alert('start new main view');
            FlyTalk.views.mainView = new FlyTalk.views.MainView();
        }

        FlyTalk.views.mainView.setActiveItem(
            FlyTalk.views.ModeSelection
        	//FlyTalk.views.Serviceperfumeire
        );
    },

	'openItinDetail': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ItinDetailView);
	},
	
	'closeItinDetailView': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ItinMapView, {type: 'slide', direction: 'right'});
	},
	
	'openServiceDetail': function (options) {
	
		switch (options.sd){
			case 'laitaliana':
				FlyTalk.views.mainView.setActiveItem(FlyTalk.views.Servicelaitaliana);
				break;
			case 'pastaperfecto':
				FlyTalk.views.mainView.setActiveItem(FlyTalk.views.Servicepastaperfecto);
				break;
			case 'perfumeire':
				FlyTalk.views.mainView.setActiveItem(FlyTalk.views.Serviceperfumeire);
				break;
			case 'guisepe':
				FlyTalk.views.mainView.setActiveItem(FlyTalk.views.Serviceguisepe);
				break;
			default:
				FlyTalk.views.mainView.setActiveItem(FlyTalk.views.Servicedefault);
		}
		
		
	},
	
	'closeServiceDetailView': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ServicesView, {type: 'slide', direction: 'right'});
	},
	
/*********************** HOME VIEW ***************************/
	// open search page
	'openSearch': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.SearchSearchView);
    },
    
    'openResult': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.SearchView);
    },
    
    'openHome': function (options) {
    	 Ext.dispatch({
             controller: FlyTalk.controllers.dbController,
             action: 'getNewNote',
         });
		//FlyTalk.views.mainView.setActiveItem(FlyTalk.views.HomeView, {type: 'slide', direction: 'left'});
    },
    
    'openReview': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ComposeView);
    },
    
    'openMap': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.MapTab);
    },
    
    'openRestaurant': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.RestaurantView);
    },
    
    'openQuestion': function (options) {
    //	alert("open question");
      	FlyTalk.views.QuestionForm.toolbar.setTitle("Ask for help");
    	FlyTalk.views.QuestionForm.items.getAt(2).value = options.keyword;
    	FlyTalk.views.QuestionForm.items.getAt(1).setTitle("Enter question here");
    	FlyTalk.views.QuestionForm.items.getAt(2).value = " ";
    	//alert("after set"+FlyTalk.views.QuestionForm.items.getAt(2).value);
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.QuestionForm);
    },
    
    'openHelp': function (options) {
		
		if (options.from == 'notif'){
			FlyTalk.views.HelpOutView.backButton.setVisible(false);
		    FlyTalk.views.HelpOutView.notifButton.setVisible(true);
		}else{
			FlyTalk.views.HelpOutView.backButton.setVisible(true);
			FlyTalk.views.HelpOutView.notifButton.setVisible(false);
			FlyTalk.views.HelpOutView.setActiveItem(FlyTalk.views.HelpOutTabAll);
			FlyTalk.views.HelpOutView.toolbartab.items.getAt(1).setPressed(0, true);
			
		}
		
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.HelpOutView);
		
    },
    
    'openComment': function (options) {
    	//alert("open question");
    	FlyTalk.views.QuestionForm.toolbar.setTitle("Post a comment");
    	FlyTalk.views.QuestionForm.items.getAt(1).setTitle("Enter question here");
    	FlyTalk.views.QuestionForm.items.getAt(2).value = " ";
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.QuestionForm);
    },
    
    'openReply': function (options) {
    //	alert(options.index);
    	//alert("open question");
    	var tab = FlyTalk.views.TalkView.toolbartab.items.getAt(1).getPressed().text;
    	var from_user;
		if(tab == "Recent Suggestions" && options.title == "Bored"){
			from_user = FlyTalk.views.ColumnView1.MixedStore.getAt(options.index).data.from_user;
		}
		else{
			from_user = FlyTalk.views.ColumnView.MixedStore.getAt(options.index).data.from_user;
		}
    	
		FlyTalk.views.QuestionForm.items.getAt(1).setTitle("Enter reply here");
		FlyTalk.views.QuestionForm.items.getAt(2).value = "@"+from_user;
    	FlyTalk.views.QuestionForm.items.getAt(3).label = options.index;
    	FlyTalk.views.QuestionForm.toolbar.setTitle("Reply");
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.QuestionForm);
    },
    
    'openSuggest': function (options) {
    	FlyTalk.views.mainView.setActiveItem(FlyTalk.views.MapView);
    },
	
	'openMytalk': function (options) {
		//FlyTalk.views.mainView.setActiveItem(FlyTalk.views.MyTalkView);
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.MyTalkView, {type: 'flip', direction: 'right'});
	},
	
	'openProfile': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ProfView);
	},
	

	'openBored': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.BoredView);
	},
	
	'openItinmap': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ItinMapView);
	},
	
	
	
	'closeRestaurantView': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ItinMapView, {type: 'slide', direction: 'right'});
	},
	
	'openService': function (options) {
		if (options.from == 'notif'){
			FlyTalk.views.ServicesView.backButton.setVisible(false);
		    FlyTalk.views.ServicesView.notifButton.setVisible(true);
		}else{
			FlyTalk.views.ServicesView.backButton.setVisible(true);
			FlyTalk.views.ServicesView.notifButton.setVisible(false);		
		}
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ServicesView);
	},
	
	'openMap': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.MapView);
	},
	
	'openSettings': function (options) {
		//alert("settings: link later");
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.SettingView, {type: 'slide', direction: 'right'});
	},
	
	// bring up the compose post window
	'openCompose': function (options) {
		alert("need to link to overlay");
		//FlyTalk.views.mainView.setActiveItem(FlyTalk.views.ComposeView, {type: 'slide', direction: 'left'});
    },
	
    // bring up the compose post window
	'openFlytalk': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.TalkView, {type: 'slide', direction: 'left'});
    },
    
    //TODO - CHANGE WORDING
    // open next page
    'openNext': function (options) {
    	if(options.next == 'Feeds'){ // in flight talk
    		FlyTalk.views.ColumnView.items.getAt(0).show();
        	FlyTalk.views.ColumnView.items.getAt(0).doComponentLayout();
			FlyTalk.views.ColumnView1.items.getAt(0).hide();
			FlyTalk.views.ColumnView1.items.getAt(0).doComponentLayout();
            Ext.dispatch({
                controller: FlyTalk.controllers.dbController,
                action: 'getMixedPosts',
                title: 'Feeds',
                tab1: 'All Feeds',
                tab2: 'My Feeds',
                method1: 'getFlightPost',
                method2: 'getMyPost',
                numtabs: 2,
                //prev: 'home',
            });
		}else if(options.next == 'Search'){
			//FlyTalk.views.SearchSearchView.reset();
			//FlyTalk.views.SearchSearchView.items.getAt(2).hide()
			FlyTalk.views.mainView.setActiveItem(FlyTalk.views.SearchSearchView, {type: 'slide', direction: 'right'});
		}else if(options.next == 'Result'){
			//alert("open next result");
			 Ext.dispatch({
		            controller: FlyTalk.controllers.dbController,
		            action: 'getSearchPost',
		            prev: 'result',
     		 });
		}
		else if(options.next == 'note'){
			FlyTalk.views.mainView.setActiveItem(FlyTalk.views.NotificationView, {type: 'slide', direction: 'right'});
		}else if(options.next == 'myFeed'){ // my talk
			Ext.dispatch({
		            controller: FlyTalk.controllers.dbController,
		            action: 'getMixedPosts',
		            title: 'myFeed',
		            tab1: 'myTalk',
		            tab2: 'Help Out',
		            method1: 'getMyPost',
		            method2: 'getHelpList', //todo: change this!
		            numtabs: 2,
		    });
		}else if(options.next == 'Bored'){ //bored
			FlyTalk.views.ColumnView.items.getAt(0).hide();
			FlyTalk.views.ColumnView.items.getAt(0).doComponentLayout();
			FlyTalk.views.ColumnView1.items.getAt(0).hide();
			FlyTalk.views.ColumnView1.items.getAt(0).doComponentLayout();
			Ext.dispatch({
	            controller: FlyTalk.controllers.dbController,
	            action: 'getMixedPosts',
	            title: 'Bored',
	            tab1: 'Popular Suggestions',
	            tab2: 'Recent Suggestions',
	            method1: 'getPopBoredPost',
	            method2: 'getRecentBoredPost', 
	            numtabs: 2,
	            
	            
	        });
		}else{ // not in talkview (details)
			
		}
    },
    
    
	'openMenu': function (options) {
		// check if the user is already following the post		
		var tab = FlyTalk.views.TalkView.toolbartab.items.getAt(1).getPressed().text;

		if(tab == "My Feeds"){
			FlyTalk.views.BoredView.incomplete.show();
		}else{
			var post;
			if(tab == "Recent Suggestions"){
				post = FlyTalk.views.ColumnView1.MixedStore.getAt(options.index).data;
			}else{
				post = FlyTalk.views.ColumnView.MixedStore.getAt(options.index).data;
			}
			
	//		if(FlyTalk.views.BoredView.opened.title != "opened"){ // only for testing purposes
	//			//FlyTalk.views.ColumnView.MixedStore.getAt(0).data.rated = -1;
	//			
	//		}else{
				// make sure all buttons are shown when starting...
				FlyTalk.views.BoredView.followButton.show();
				FlyTalk.views.BoredView.unfollowButton.show();
				FlyTalk.views.BoredView.upButton.show();
				FlyTalk.views.BoredView.downButton.show();
				FlyTalk.views.BoredView.threadButton.show();
				FlyTalk.views.BoredView.replyButton.show();
				FlyTalk.views.BoredView.askButton.hide();
				FlyTalk.views.BoredView.suggestButton.hide();
				FlyTalk.views.BoredView.reviewButton.hide();
				FlyTalk.views.BoredView.commentButton.hide();
				FlyTalk.views.BoredView.locButton.show();
				FlyTalk.views.BoredView.undoButton.show();
				FlyTalk.views.BoredView.locButton.doComponentLayout();
				FlyTalk.views.BoredView.followButton.doComponentLayout();
				FlyTalk.views.BoredView.unfollowButton.doComponentLayout();
				FlyTalk.views.BoredView.upButton.doComponentLayout();
				FlyTalk.views.BoredView.downButton.doComponentLayout();
				FlyTalk.views.BoredView.threadButton.doComponentLayout();
				FlyTalk.views.BoredView.replyButton.doComponentLayout();
				
				//alert("follow: "+post.followed);
				
				// customize follow button
				if(post.followed == "<img src='images/orange_start.png' height='10px' width='10px'>"){ // already follwing a post, then unfollow button shows up
					FlyTalk.views.BoredView.followButton.hide();
				}else{ // not follwing a post, then follow button shows up
					FlyTalk.views.BoredView.unfollowButton.hide();
				}
				
				FlyTalk.views.BoredView.undoButton.doComponentLayout();
				// customize thumbs up and down buttons
				if(post.rated == 1 || post.rated == 2){   // if already rated, then don't show any thumbs up or down button
					FlyTalk.views.BoredView.upButton.hide();
					FlyTalk.views.BoredView.downButton.hide();
					if(post.rated == 1){
						FlyTalk.views.BoredView.undoButton.update({src: "images/post_undoUp.png"});
						//FlyTalk.views.BoredView.undoButton.setText("Undo thumbs up");
					}else{
						FlyTalk.views.BoredView.undoButton.update({src: "images/post_undoDown.png"});
					}
					FlyTalk.views.BoredView.undoButton.show();
					FlyTalk.views.BoredView.undoButton.doComponentLayout();
				}else{
					FlyTalk.views.BoredView.undoButton.hide();
				}
				
				// customize see convo button
				if(post.answered != "yes"){// only display see convo button if the post is a convo
					FlyTalk.views.BoredView.threadButton.hide();
				}
				
				// customize see convo button
				if(post.type == "suggested"){// only display see convo button if the post is a convo
					FlyTalk.views.BoredView.replyButton.hide();
					FlyTalk.views.BoredView.followButton.hide();
				}
				
				// customize reply button
				//alert("from: "+post.from_uid);
				if(post.from_uid == 3 && FlyTalk.views.MapView.items.first().hidden == true){// only display see convo button if the post is a convo
					FlyTalk.views.BoredView.replyButton.hide();
				}
				
				if(post.tp == ""){
					FlyTalk.views.BoredView.locButton.hide();
				}
				
				// pass the index of this variable to the panel
				FlyTalk.views.BoredView.ind.title = options.index;
	//		}
			
			// show the overlay when the user click on the + button
			
			setTimeout('FlyTalk.views.BoredView.overlay.show()',5);		
		}
    },
    
    'openThreadMenu': function (options) {
		// check if the user is already following the post
		var post = FlyTalk.views.PostView.MixedStore.getAt(options.index).data;
		FlyTalk.views.BoredView.followButton.show();
		FlyTalk.views.BoredView.unfollowButton.show();
		FlyTalk.views.BoredView.upButton.show();
		FlyTalk.views.BoredView.downButton.show();
		FlyTalk.views.BoredView.threadButton.show();
		FlyTalk.views.BoredView.replyButton.show();
		FlyTalk.views.BoredView.askButton.hide();
		FlyTalk.views.BoredView.suggestButton.hide();
		FlyTalk.views.BoredView.reviewButton.hide();
		FlyTalk.views.BoredView.commentButton.hide();
		FlyTalk.views.BoredView.locButton.show();
		FlyTalk.views.BoredView.undoButton.show();
		FlyTalk.views.BoredView.locButton.doComponentLayout();
		FlyTalk.views.BoredView.followButton.doComponentLayout();
		FlyTalk.views.BoredView.unfollowButton.doComponentLayout();
		FlyTalk.views.BoredView.upButton.doComponentLayout();
		FlyTalk.views.BoredView.downButton.doComponentLayout();
		FlyTalk.views.BoredView.threadButton.doComponentLayout();
		FlyTalk.views.BoredView.replyButton.doComponentLayout();
		
		//alert("follow: "+post.followed);
		
		// customize follow button
		if(post.followed == "<img src='images/orange_start.png' height='10px' width='10px'>"){ // already follwing a post, then unfollow button shows up
			FlyTalk.views.BoredView.followButton.hide();
		}else{ // not follwing a post, then follow button shows up
			FlyTalk.views.BoredView.unfollowButton.hide();
		}
		
		FlyTalk.views.BoredView.undoButton.doComponentLayout();
		// customize thumbs up and down buttons
		if(post.rated == 1 || post.rated == 2){   // if already rated, then don't show any thumbs up or down button
			FlyTalk.views.BoredView.upButton.hide();
			FlyTalk.views.BoredView.downButton.hide();
			if(post.rated == 1){
				FlyTalk.views.BoredView.undoButton.update({src: "images/post_undoUp.png"});
				//FlyTalk.views.BoredView.undoButton.setText("Undo thumbs up");
			}else{
				FlyTalk.views.BoredView.undoButton.update({src: "images/post_undoDown.png"});
			}
			FlyTalk.views.BoredView.undoButton.show();
			FlyTalk.views.BoredView.undoButton.doComponentLayout();
		}else{
			FlyTalk.views.BoredView.undoButton.hide();
		}
		
		// customize see convo button
		if(post.answered != "yes"){// only display see convo button if the post is a convo
			FlyTalk.views.BoredView.threadButton.hide();
		}
		
		// customize see convo button
		if(post.type == "suggested"){// only display see convo button if the post is a convo
			FlyTalk.views.BoredView.replyButton.hide();
			FlyTalk.views.BoredView.followButton.hide();
		}
		
		// customize reply button
		//alert("from: "+post.from_uid);
		if(post.from_uid == 3 && FlyTalk.views.MapView.items.first().hidden == true){// only display see convo button if the post is a convo
			FlyTalk.views.BoredView.replyButton.hide();
		}
		
		if(post.tp == ""){
			FlyTalk.views.BoredView.locButton.hide();
		}
		
		// pass the index of this variable to the panel
		FlyTalk.views.BoredView.ind.title = options.index;
//		}
	
	// show the overlay when the user click on the + button
	
	setTimeout('FlyTalk.views.BoredView.overlay.show()',5);	
    },
    
    'openSearchMenu': function (options) {
		// check if the user is already following the post
		var post = FlyTalk.views.SearchPostView.MixedStore.getAt(options.index).data;
		
		
//		if(FlyTalk.views.BoredView.opened.title != "opened"){ // only for testing purposes
//			//FlyTalk.views.ColumnView.MixedStore.getAt(0).data.rated = -1;
//			
//		}else{
			// make sure all buttons are shown when starting...
			FlyTalk.views.BoredView.followButton.show();
			FlyTalk.views.BoredView.unfollowButton.show();
			FlyTalk.views.BoredView.upButton.show();
			FlyTalk.views.BoredView.downButton.show();
			FlyTalk.views.BoredView.threadButton.show();
			FlyTalk.views.BoredView.replyButton.show();
			FlyTalk.views.BoredView.locButton.show();
			FlyTalk.views.BoredView.askButton.hide();
			FlyTalk.views.BoredView.undoButton.show();
			FlyTalk.views.BoredView.suggestButton.hide();
			FlyTalk.views.BoredView.reviewButton.hide();
			FlyTalk.views.BoredView.commentButton.hide();
			FlyTalk.views.BoredView.followButton.doComponentLayout();
			FlyTalk.views.BoredView.unfollowButton.doComponentLayout();
			FlyTalk.views.BoredView.upButton.doComponentLayout();
			FlyTalk.views.BoredView.downButton.doComponentLayout();
			FlyTalk.views.BoredView.threadButton.doComponentLayout();
			FlyTalk.views.BoredView.replyButton.doComponentLayout();
			FlyTalk.views.BoredView.locButton.doComponentLayout();
			
			
			// customize follow button
			if(post.followed == "<img src='images/orange_start.png' height='10px' width='10px'>"){ // already follwing a post, then unfollow button shows up
				FlyTalk.views.BoredView.followButton.hide();
			}else{ // not follwing a post, then follow button shows up
				FlyTalk.views.BoredView.unfollowButton.hide();
			}
			
			FlyTalk.views.BoredView.undoButton.doComponentLayout();
			// customize thumbs up and down buttons
			if(post.rated == 1 || post.rated == 2){   // if already rated, then don't show any thumbs up or down button
				FlyTalk.views.BoredView.upButton.hide();
				FlyTalk.views.BoredView.downButton.hide();
				if(post.rated == 1){
					FlyTalk.views.BoredView.undoButton.setText("Undo thumbs up");
				}else{
					FlyTalk.views.BoredView.undoButton.setText("Undo thumbs down");
				}
				
				FlyTalk.views.BoredView.undoButton.show();
				FlyTalk.views.BoredView.undoButton.doComponentLayout();
			}else{
				FlyTalk.views.BoredView.undoButton.hide();
			}
			
			// customize see convo button
			if(post.answered != "yes"){// only display see convo button if the post is a convo
				FlyTalk.views.BoredView.threadButton.hide();
			}
			
			// customize see convo button
			if(post.type == "suggested"){// only display see convo button if the post is a convo
				FlyTalk.views.BoredView.replyButton.hide();
				FlyTalk.views.BoredView.followButton.hide();
			}
			
			// customize reply button
			//alert("from: "+post.from_uid);
			if(post.from_uid == 3 && FlyTalk.views.MapView.items.first().hidden == true){// only display see convo button if the post is a convo
				FlyTalk.views.BoredView.replyButton.hide();
			}
			
			
			if(post.tp == ""){
				FlyTalk.views.BoredView.locButton.hide();
			}
			
			// pass the index of this variable to the panel
			FlyTalk.views.BoredView.ind.title = options.index;
//		}
		
		// show the overlay when the user click on the + button
		
		setTimeout('FlyTalk.views.BoredView.overlay.show()',5);		
    },
    
    'openPlus': function (options) {
    	FlyTalk.views.BoredView.askButton.show();
		FlyTalk.views.BoredView.suggestButton.hide();
		FlyTalk.views.BoredView.reviewButton.hide();
		FlyTalk.views.BoredView.commentButton.show();
		FlyTalk.views.BoredView.followButton.hide();
		FlyTalk.views.BoredView.unfollowButton.hide();
		FlyTalk.views.BoredView.upButton.hide();
		FlyTalk.views.BoredView.downButton.hide();
		FlyTalk.views.BoredView.threadButton.hide();
		FlyTalk.views.BoredView.undoButton.hide();
		FlyTalk.views.BoredView.replyButton.hide();
		FlyTalk.views.BoredView.locButton.hide();
		FlyTalk.views.BoredView.plus.show();	
		FlyTalk.views.BoredView.doComponentLayout();
		//FlyTalk.views.BoredView.suggestButton.doComponentLayout();
		FlyTalk.views.BoredView.askButton.doComponentLayout();
		FlyTalk.views.BoredView.commentButton.doComponentLayout();
	//	FlyTalk.views.BoredView.reviewButton.doComponentLayout();
    },
    
    'openPlusSuggest': function (options) {
		FlyTalk.views.BoredView.suggestButton.show();
		FlyTalk.views.BoredView.suggestButton.doComponentLayout();
    	FlyTalk.views.BoredView.askButton.hide();
		FlyTalk.views.BoredView.reviewButton.hide();
		FlyTalk.views.BoredView.commentButton.hide();
		FlyTalk.views.BoredView.followButton.hide();
		FlyTalk.views.BoredView.undoButton.hide();
		FlyTalk.views.BoredView.unfollowButton.hide();
		FlyTalk.views.BoredView.upButton.hide();
		FlyTalk.views.BoredView.downButton.hide();
		FlyTalk.views.BoredView.threadButton.hide();
		FlyTalk.views.BoredView.replyButton.hide();
		FlyTalk.views.BoredView.locButton.hide();
		FlyTalk.views.BoredView.plusBored.show();	
		FlyTalk.views.BoredView.doComponentLayout();

    },
	
	
/*********************** SEARCH VIEW ***************************/
	// display tweetDeck
	'toTweetDeck1': function (options) {
		FlyTalk.views.TalkView.setActiveItem(FlyTalk.views.ColumnView, {type: 'slide', direction: 'right'});
    },
	
	// search posts and open a new page
	'searchPosts': function (options) {
		//alert(FlyTalk.views.TalkView.items.length);
		//alert("search ft");
		var newpage = "";
		var index = FlyTalk.views.TalkView.items.length-2;
		// add the view to the app
		if (!FlyTalk.views.searchResultsView) {
		//	alert('create search result 0');
            FlyTalk.views.searchResultsView = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView;	
        }else if(!FlyTalk.views.searchResultsView1){
			//alert('create search result 1');
			FlyTalk.views.searchResultsView1 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView1;
		}else if(!FlyTalk.views.searchResultsView2){
			//alert('create search result 2');
			FlyTalk.views.searchResultsView2 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView2;
		}else if(!FlyTalk.views.searchResultsView3){
			//alert('create search result 3');
			FlyTalk.views.searchResultsView3 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView3;
		}else if(!FlyTalk.views.searchResultsView4){
			//alert('create search result 4');
			FlyTalk.views.searchResultsView4 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView4;
		}else if(!FlyTalk.views.searchResultsView5){
			//alert('create search result 5');
			FlyTalk.views.searchResultsView5 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView5;
		}else if(!FlyTalk.views.searchResultsView6){
			//alert('create search result 6');
			FlyTalk.views.searchResultsView6 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView6;
		}else if(!FlyTalk.views.searchResultsView7){
			//alert('create search result 7');
			FlyTalk.views.searchResultsView7 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView7;
		}else if(!FlyTalk.views.searchResultsView8){
			//alert('create search result 8');
			FlyTalk.views.searchResultsView8 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView8;
		}else if(!FlyTalk.views.searchResultsView9){
			//alert('create search result 9');
			FlyTalk.views.searchResultsView9 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView9;
		}else if(!FlyTalk.views.searchResultsView10){
			//alert('create search result 10');
			FlyTalk.views.searchResultsView10 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView10;
		}else if(!FlyTalk.views.searchResultsView11){
			//alert('create search result 11');
			FlyTalk.views.searchResultsView11 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView11;
		}else if(!FlyTalk.views.searchResultsView12){
			//alert('create search result 12');
			FlyTalk.views.searchResultsView12 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView12;
		}else if(!FlyTalk.views.searchResultsView13){
			//alert('create search result 13');
			FlyTalk.views.searchResultsView13 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView13;
		}else if(!FlyTalk.views.searchResultsView14){
			//alert('create search result 14');
			FlyTalk.views.searchResultsView14 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView14;
		}else if(!FlyTalk.views.searchResultsView15){
			//alert('create search result 15');
			FlyTalk.views.searchResultsView15 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView15;
		}else if(!FlyTalk.views.searchResultsView16){
			//alert('create search result 16');
			FlyTalk.views.searchResultsView16 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView16;
		}else if(!FlyTalk.views.searchResultsView17){
			//alert('create search result 17');
			FlyTalk.views.searchResultsView17 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView17;
		}else if(!FlyTalk.views.searchResultsView18){
			//alert('create search result 18');
			FlyTalk.views.searchResultsView18 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView18;
		}else if(!FlyTalk.views.searchResultsView19){
			//alert('create search result 19');
			FlyTalk.views.searchResultsView19 = new FlyTalk.views.SearchResultsView();
			newpage = FlyTalk.views.searchResultsView19;
		}
	
		// if not at last page, create a new page and display search results
		if(newpage != ""){
			//alert(options.scope);
			// add the search result page to the carousel
			
			// search for the tweets
			FlyTalk.views.TalkView.insert(index,  newpage);
			
			
			var store = new Ext.data.JsonStore({
				model : 'PostModel',
				autoLoad: true,

				proxy: {
          			type: 'scripttag',
          			url: 'http://search.twitter.com/search.json',
          			extraParams: {
             			q: "chair",
                		rpp: 3,
                		//suppress_response_codes: true
          			},
          			reader: {
                		type: 'json',
                		root: 'results',
						totalProperty: 'totalCount' 
         			}
    			},})
				
			/*
			var store = new Ext.data.JsonStore({
				model : 'UserModel',
				autoload: true,
				proxy: {
          			type: 'ajax',
          			url: '/db/dbRetrieveMultiple.php',
          			reader: {
                		type: 'json',
                		root: 'results'
         			}
    			},
			});*/
			//store.load();
			newpage.tweetList.bindStore(store);
			
				
			//alert(store.proxy.reader.rawData.totalCount);
	
			// update TalkView
			FlyTalk.views.TalkView.doLayout();
			
			// display the search result page
			FlyTalk.views.TalkView.setActiveItem(newpage, {type: 'slide', direction: 'right'});
		}else{
				alert("not loading");
		}
    },// end of search posts 1

/*********************** COLUMN VIEW ***************************/
	
	// open thread on a new page
	'openThread': function (options) {
		FlyTalk.views.PostView.tweetPanel.update(options.post);
	//	FlyTalk.views.PostView.doComponentLayout();
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.PostView, {type: 'slide', direction: 'left'});
    },
    
    // open location on a new page
	'openLoc': function (options) {
		var next = FlyTalk.views.TalkView.tweetToolbar.title; 
		var f;
		if(next == "Feeds" || next == "Bored")
			//f = FlyTalk.views.ColumnView.MixedStore.getAt(options.index).data.fid;
		
			var tab = null;
			if(FlyTalk.views.TalkView.tabBar.activeTab != null){
				tab = FlyTalk.views.TalkView.tabBar.activeTab.text;
			}
			if(tab == "Recent Suggestions" || tab == "My Feeds"){
				f = FlyTalk.views.ColumnView1.MixedStore.getAt(options.index).data.fid;
			}
			else{
				f = FlyTalk.views.ColumnView.MixedStore.getAt(options.index).data.fid;
			}
		
		if(next == "Result")
			f = FlyTalk.views.SearchPostView.MixedStore.getAt(options.index).data.fid;
		if(next == "note")
			f = FlyTalk.views.PostView.MixedStore.getAt(options.index).data.fid;
		
		switch (f){
		case 137:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_pasta.png"></img></div>');
			break;
		case 138:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_guisepe.png"></img></div>');
			break;
		case 139:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_pasta.png"></img></div>');
			break;
		case 140:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_laItalian.png"></img></div>');
			break;
		case 141:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_laItalian.png"></img></div>');
			break;
		case 142:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_laItalian.png"></img></div>');
			break;
		case 143:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_prato.png"></img></div>');
			break;
		case 144:
			Ext.get('locImage').update('<div><img id="tp" src="./images/map_post_museum.png"></img></div>');
			break;
		default:
			Ext.get('locImage').update('No Information to Show');
	}
	FlyTalk.views.LocView.toolbar.setTitle("Location");

	FlyTalk.views.mainView.setActiveItem(FlyTalk.views.LocView);
	
	//	FlyTalk.views.PostView.doComponentLayout();
	//	FlyTalk.views.mainView.setActiveItem(FlyTalk.views.PostView, {type: 'slide', direction: 'left'});
    },
	
	// open thread on a new page
	'deletePanel': function (options) {
		FlyTalk.views.TalkView.remove(options.panel);
		options.panel.destroy();
		
	//	FlyTalk.views.PostView.doComponentLayout();
		FlyTalk.views.TalkView.setActiveItem(FlyTalk.views.ColumnView, {type: 'slide', direction: 'left'});
    },
	
	
/*********************** POST VIEW ***************************/
	// post msg
	'postMsg': function (options) {
		//alert(options.scope);
		//alert(options.msg);
	
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.TalkView, {type: 'slide', direction: 'right'});
    },
	
	// display tweetDeck
	'toTweetDeck': function (options) {
		FlyTalk.views.mainView.setActiveItem(FlyTalk.views.TalkView, {type: 'slide', direction: 'right'});
    },

});

FlyTalk.controllers.ftController = Ext.ControllerManager.get('ftController');